//  选择开关类型按钮
//  YZEUIButtonChoose.m
//  yilutongxing
//
//  Created by T&J on 2017/6/9.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "YZEUIButtonChoose.h"

#define BUTTON_COLOR_NORMAL [UIColor colorWithRed:60/255.0 green:60/255.0 blue:60/255.0 alpha:1.0]

@implementation YZEUIButtonChoose

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self didInitialize];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title{
    if (self = [super init]) {
        CGSize size = [self sizeThatFits:self.frame.size];
        size.width += 20;
        self.size = size;
        [self setTitle:title forState:UIControlStateNormal];
    }
    return self;
}

- (void)didInitialize{
    self.selected = NO;
    [self setBackgroundImage:[UIImage imageNamed:@"日常指标未选"] forState:UIControlStateNormal];
    [self setTitleColor:BUTTON_COLOR_NORMAL forState:UIControlStateNormal];
    [self.titleLabel setFont:[UIFont systemFontOfSize:15]];
}

- (void)setSelected:(BOOL)selected{
    if (selected) {
        [self setBackgroundImage:[UIImage imageNamed:@"日常指标已选"] forState:UIControlStateSelected];
        [self setTitleColor:WHITE_COLOR forState:UIControlStateSelected];
    }
    else {
        [self setBackgroundImage:[UIImage imageNamed:@"日常指标未选"] forState:UIControlStateNormal];
        [self setTitleColor:BUTTON_COLOR_NORMAL forState:UIControlStateNormal];
    }
    super.selected = selected;
}

- (BOOL)getSelected{
    return super.selected;
}

- (void)setHighlighted:(BOOL)highlighted{
    //阻止长按时变灰效果，故意留空
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
